#include "flowcontrol.h"
#include "common.h"
#include "iCode.h"
extern char labelbuffer[MAX_LENGTH_BUFFER];
extern int NestLevel;

void createLogicalOr(struct operand *op, int label)
{
	symbol *_trueLab;
    op = geniCodeRValue(op, false);
	sprintf(labelbuffer, "%s%d", L_TRUE, label);
	_trueLab = newSymbol(labelbuffer, NestLevel);
	geniCodeIfx(op, _trueLab, NULL); 
    //gen	( "NE",       val->name, "0" 	);
    //gen	( "goto%s%d", L_TRUE,	 label	);
    //release_value( val );
}

void createLogicalAnd(struct operand *op, int label)
{
	struct symbol *_falseLab;
    op = geniCodeRValue(op, false);
	sprintf(labelbuffer, "%s%d", L_FALSE, label);
	_falseLab = newSymbol(labelbuffer, NestLevel);
	geniCodeIfx(op, NULL, _falseLab); 
}

struct operand *gen_false_true(int labelnum, struct operand *op)
{
	if( !op )
		op = newiTempOperand(newCharLink(), false);

	sprintf(labelbuffer, "%s%d", L_FALSE, labelnum);
	geniCodeLabelFromName(labelbuffer);

	geniCodeAssign(op, operandFromValue(valueFromLit(0)));

	sprintf(labelbuffer, "%s%d", L_END, labelnum);
	geniCodeGotoFromName(labelbuffer);

	sprintf(labelbuffer, "%s%d", L_TRUE, labelnum);
	geniCodeLabelFromName(labelbuffer);

	geniCodeAssign(op, operandFromValue(valueFromLit(1)));

	sprintf(labelbuffer, "%s%d", L_END, labelnum);
	geniCodeLabelFromName(labelbuffer);
    
	return op;
}



int tf_label()
{
	static int label;
	return ++label;
}